home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic Source Code
/
Visual Basic Source Code.iso
/
vbsource
/
dtadmo
/
form2.frm
< prev
next >
Wrap
Text File
|
1994-10-15
|
8KB
|
293 lines
VERSION 2.00
Begin Form Form2
Caption = "Form2"
ClientHeight = 4260
ClientLeft = 1110
ClientTop = 1500
ClientWidth = 7365
Height = 4665
Left = 1050
LinkTopic = "Form2"
ScaleHeight = 4260
ScaleWidth = 7365
Top = 1155
Width = 7485
Begin CommandButton cmdClose
Caption = "Close"
Height = 495
Left = 120
TabIndex = 14
Top = 3480
Width = 1455
End
Begin CommandButton cmdDelete
Caption = "Delete"
Height = 495
Left = 6120
TabIndex = 13
Top = 3480
Width = 1215
End
Begin CommandButton cmdUpdate
Caption = "Update"
Height = 495
Left = 4440
TabIndex = 12
Top = 3480
Width = 1215
End
Begin CommandButton cmdNew
Caption = "New"
Height = 495
Left = 3120
TabIndex = 11
Top = 3480
Width = 1215
End
Begin CommandButton cmdFind
Caption = "Find"
Height = 495
Left = 1800
TabIndex = 10
Top = 3480
Width = 1215
End
Begin TextBox Text1
DataSource = "Data1"
Height = 495
Index = 4
Left = 1800
TabIndex = 4
Text = "Text1"
Top = 2520
Width = 1215
End
Begin TextBox Text1
DataSource = "Data1"
Height = 495
Index = 3
Left = 1800
TabIndex = 3
Text = "Text1"
Top = 1920
Width = 1215
End
Begin TextBox Text1
DataSource = "Data1"
Height = 495
Index = 2
Left = 1800
TabIndex = 2
Text = "Text1"
Top = 1320
Width = 1215
End
Begin TextBox Text1
DataSource = "Data1"
Height = 495
Index = 1
Left = 1800
TabIndex = 1
Text = "Text1"
Top = 720
Width = 1215
End
Begin TextBox Text1
DataSource = "Data1"
Height = 495
Index = 0
Left = 1800
TabIndex = 0
Text = "Text1"
Top = 120
Width = 5295
End
Begin Data Data1
Caption = "Data1"
Connect = ""
DatabaseName = ""
Exclusive = 0 'False
Height = 270
Left = 1800
Options = 0
ReadOnly = 0 'False
RecordSource = ""
Top = 3120
Width = 3855
End
Begin Label Label1
Caption = "Label1"
Height = 495
Index = 4
Left = 480
TabIndex = 9
Top = 2520
Width = 1215
End
Begin Label Label1
Caption = "Label1"
Height = 495
Index = 3
Left = 480
TabIndex = 8
Top = 1920
Width = 1215
End
Begin Label Label1
Caption = "Label1"
Height = 495
Index = 2
Left = 480
TabIndex = 7
Top = 1320
Width = 1215
End
Begin Label Label1
Caption = "Label1"
Height = 495
Index = 1
Left = 480
TabIndex = 6
Top = 720
Width = 1215
End
Begin Label Label1
Caption = "Label1"
Height = 495
Index = 0
Left = 480
TabIndex = 5
Top = 120
Width = 1215
End
End
Option Explicit
Sub cmdClose_Click ()
Unload form2
'database is closed in the form unload event
End Sub
Sub cmdDelete_Click ()
'reminder:
'Global Const MB_YESNO = 4 ' Yes and No buttons
'Global Const IDYES = 6 ' Yes button pressed
'Global Const MB_DEFBUTTON2 = 256 ' Second button is default
On Error GoTo cmddeleteERR
Dim response As Integer
response = MsgBox("Are sure you want to delete " & text1(0).Text & " ?", MB_YESNO + MB_DEFBUTTON2)
If response = IDYES Then
data1.Recordset.Delete
'refresh so our deleted record isn't still showing
'on screen
data1.Refresh
End If
GoTo cmddeleteEND
cmddeleteERR:
showerror
Resume cmddeleteEND
cmddeleteEND:
End Sub
Sub cmdFind_Click ()
On Error GoTo cmdfindERR
Dim MyCriteria As String
Dim sql As String
'construct a query to put the table in name order
sql = "select * from [Place Names] order by Name"
data1.RecordSource = sql
'refresh the datacontrol with the new order
data1.Refresh
'get a name to look for
MyCriteria = "Name >= '" & InputBox$("Name to find:") & "'"
'look for the name
'and find first matching record.
data1.Recordset.FindFirst MyCriteria
'if not found, say so and point to the first valid record
If data1.Recordset.NoMatch Then
MsgBox "record not found"
data1.Recordset.MoveFirst
End If
GoTo cmdfindEND
cmdfindERR:
showerror
Resume cmdfindEND
cmdfindEND:
End Sub
Sub cmdNew_Click ()
On Error GoTo cmdnewERR
data1.Recordset.AddNew
text1(0).SetFocus
GoTo cmdnewEND
cmdnewERR:
showerror
Resume cmdnewEND
cmdnewEND:
End Sub
Sub cmdUpdate_Click ()
On Error GoTo cmdupdateERR
data1.Recordset.Update
GoTo cmdupdateEND
cmdupdateERR:
showerror
Resume cmdupdateEND
cmdupdateEND:
End Sub
Sub Form_Load ()
On Error GoTo formERR
Dim i As Integer
'set the database name to the data control
data1.DatabaseName = ThePath + "USPLACE.MDB"
'point the data control to our table
data1.RecordSource = "Place Names"
'open it up
data1.Refresh
'just to show it can be done, get the labels
'and field names from the tabledefs object.
'you could also hard code them, or set them in
'the properties window
For i = 0 To 4
label1(i).Caption = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
text1(i).DataField = data1.Database.TableDefs("Place Names").Fields(i + 1).Name
Next i
'note -- our table is now in primary key
'order at this point.
'The code in the find button event puts it in
'name order before executing the findfirst
GoTo formEND
formERR:
showerror
Resume formEND
formEND:
End Sub
Sub Form_Unload (Cancel As Integer)
On Error GoTo unloadERR
data1.Recordset.Close
GoTo unloadEND
unloadERR:
showerror
Resume unloadEND
unloadEND:
End Sub